package com.tddx.activiti.redis.controller;

import java.io.Serializable;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tddx.activiti.redis.service.RedisService;

@RequestMapping("redis")
@Controller
public class RedisController {
	
	@Autowired private RedisTemplate<Serializable, Object> redisTemplate;
	
	private static ValueOperations<Serializable, Object> operations; 
	
	@Autowired private RedisService service;
	
	@RequestMapping("demo1")
	@ResponseBody
	public Object demo1(@RequestParam Map<String, String> map){
		return service.demo1(map.get("id"));
	}
	
	@RequestMapping("demo2")
	@ResponseBody
	public Object demo2(@RequestParam Map<String, String> map){
		return service.demo2(map.get("id"));
	}
	
	@RequestMapping("demo3")
	@ResponseBody
	public Object demo3(@RequestParam Map<String, String> map){
		operations = redisTemplate.opsForValue();
		operations.set("a", "A");
		System.out.println(operations.get("a"));
		return map;
	}
	
}
